package com.example.elmmerchants.Message_Setting;

import android.app.Service;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.IBinder;

import com.example.elmmerchants.R;

public class Message_Ringtone extends Service {

    private MediaPlayer mediaPlayer;
    String which_message_type;
    AudioManager mAudio;

    public Message_Ringtone() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        which_message_type = intent.getStringExtra("message_ringtone");
        if (which_message_type.equals("首次提醒")) {
            mediaPlayer = MediaPlayer.create(this, R.raw.message_first_time_reminder_ringtone);
        }
        else if (which_message_type.equals("1分钟未回复提醒")) {
            mediaPlayer = MediaPlayer.create(this, R.raw.message_one_min_reminder_ringtone);
        }
        else if (which_message_type.equals("3分钟未回复提醒")) {
            mediaPlayer = MediaPlayer.create(this, R.raw.message_three_min_reminder_ringtone);
        }
        if (!mediaPlayer.isPlaying()) {
            mediaPlayer.start();
        }
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
        }
        mediaPlayer.release();
    }
}